package com.qianlou.controller;

import com.qianlou.common.enums.YesOrNo;
import com.qianlou.common.result.BaseResponse;
import com.qianlou.pojo.bo.QuestionLibBO;
import com.qianlou.service.QuestionLibService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/questionLib")
public class QuestionLibController {

    @Resource
    private QuestionLibService questionLibService;

    @PostMapping("/createOrUpdate")
    public BaseResponse createOrUpdate(@RequestBody @Valid QuestionLibBO questionLibBO) {
        questionLibService.createOrUpdate(questionLibBO);
        return BaseResponse.ok();
    }

    @GetMapping("/list")
    public BaseResponse list(@RequestParam("aiName") String aiName,
                             @RequestParam("question") String question,
                             @RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return BaseResponse.ok(questionLibService.selectQuestionLibList(aiName, question, page, pageSize));
    }

    @PostMapping("/show")
    public BaseResponse show(@RequestParam("questionLibId") String questionLibId) {
        if (StringUtils.isBlank(questionLibId)) {
            return BaseResponse.error();
        }
        questionLibService.display(questionLibId, YesOrNo.YES.getType());
        return BaseResponse.ok();
    }
    @PostMapping("/hide")
    public BaseResponse hide(@RequestParam("questionLibId") String questionLibId) {
        if (StringUtils.isBlank(questionLibId)) {
            return BaseResponse.error();
        }
        questionLibService.display(questionLibId, YesOrNo.NO.getType());
        return BaseResponse.ok();
    }

    @PostMapping("/delete")
    public BaseResponse delete(@RequestParam("questionLibId") String questionLibId) {
        if (StringUtils.isBlank(questionLibId)) {
            return BaseResponse.error();
        }
        questionLibService.removeById(questionLibId);
        return BaseResponse.ok();
    }

}